package com.cooksys.film_rental.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.cooksys.film_rental.model.forms.FilmSearchForm;

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping(value = "/")
@SessionAttributes({ "filmSearchForm" })
public class HomeController {

	@RequestMapping(method = RequestMethod.GET)
	public String homeRedirect(ModelMap model) {

		return "homeRedirectView";
	}

	@RequestMapping(value = "/home/*", method = RequestMethod.GET)
	public String homeWildcardRedirect(ModelMap model) {

		return "homeRedirectView";
	}

	@RequestMapping(value = "/home", method = RequestMethod.GET)
	public String home(ModelMap model) {

		return "loggedOutHomeView";
	}

	@ModelAttribute("filmSearchForm")
	private FilmSearchForm initFilmSearchForm() {
		FilmSearchForm filmSearchForm = new FilmSearchForm();
		return filmSearchForm;
	}

}
